Skip to content

Implementing product type constants #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2025

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Jul 9, 2025

Changes proposed in this Pull Request:

Since WC 9.7 is our current minimum version, we can implement the new constants for product types.

Testing instructions

Code review. Check if the tests are still passing.


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@wjrosa wjrosa mentioned this pull request Jul 9, 2025
6 tasks
@wjrosa wjrosa self-assigned this Jul 9, 2025
@wjrosa wjrosa marked this pull request as ready for review July 9, 2025 12:53
@wjrosa wjrosa added this to the 9.8.0 milestone Jul 21, 2025
@wjrosa wjrosa requested review from a team, daledupreez and Mayisha and removed request for a team July 21, 2025 20:58
Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me! I have one suggestion for the changelog entry for clarity, and a non-blocking comment that is driven by a personal style preference so doesn't need action.

@@ -92,7 +95,7 @@ public function ajax_add_to_cart() {
// First empty the cart to prevent wrong calculation.
WC()->cart->empty_cart();

if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
if ( ( ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much non-blocking personal preference (which may be worth discussing as a team): I prefer using fully-qualified references inline as much as possible, mostly because it's not always easy to understand what the class is when viewing isolated sections of the code, especially via diffs.

Suggested change
if ( ( ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
if ( ( Automattic\WooCommerce\Enums\ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! To add to this, I found a page with a nice discussion about it: https://www.sitepoint.com/community/t/using-namespace-prefix-versus-use-statement/351357/11

@wjrosa wjrosa enabled auto-merge (squash) July 22, 2025 10:49
@wjrosa wjrosa merged commit 0241caf into develop Jul 22, 2025
52 of 53 checks passed
@wjrosa wjrosa deleted the dev/implementing-product-type-constants branch July 22, 2025 11:04
Copy link

📈 PHP Unit Code Coverage Report

Package Line Rate Health
includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php 4%
includes/payment-methods/class-wc-stripe-express-checkout-helper.php 23%
Summary 45% (7685 / 16912)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants